package designModal;

/**
 * 静态动态 代理模式
 *
 * Author: shen qi han
 * Date: 2022/4/8 下午4:55
 */
public class ProxyByStaticMain {

    interface ITask{
        public void doTask();
    }

    class Worker implements ITask{
        @Override
        public void doTask() {
            System.out.println("working....");
        }
    }

    class WorkerProxy implements ITask{
        private ITask task;
        public WorkerProxy(ITask task){
            this.task = task;
        }
        @Override
        public void doTask() {
            System.out.println("before work.");
            task.doTask();
            System.out.println("after work.");
        }
    }

    public void demo(){
        // need static new instance
        WorkerProxy proxy = new WorkerProxy(new Worker());
        proxy.doTask();
    }

    public static void main(String[] args) {
        ProxyByStaticMain main = new ProxyByStaticMain();
        main.demo();
    }

}
